﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using ComModel;
namespace ComDAL
{
    public class xiandal
    {
        string strConn = ConfigurationManager.ConnectionStrings["myDB"].ToString();

        /// <summary>
        /// tb_board（版面信息表）显示
        /// </summary>
        /// <returns></returns>
        public List<ComModel.boardModel> showboard()
        {
            SqlConnection conn = new SqlConnection(strConn);
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from tb_board", conn);
            SqlDataReader reader = cmd.ExecuteReader();

            List<boardModel> list = new List<boardModel>();

            while (reader.Read())
            {
                boardModel s = new boardModel();
                s.board_id = Convert.ToInt32(reader["board_id"]);
                s.board_name = reader["board_name"].ToString();
                s.board_master = reader["board_master"].ToString();
                s.board_pcard = reader["board_pcard"].ToString();

                list.Add(s);
            }

            return list;


        }



        /// <summary>
        /// tb_board（版面信息表）显示
        /// </summary>
        /// <returns></returns>
        public List<ContentModel> showContent()
        {
            SqlConnection conn = new SqlConnection(strConn);
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from [tb_bbsContent]", conn);
            SqlDataReader reader = cmd.ExecuteReader();

            List<ContentModel> list = new List<ContentModel>();

            while (reader.Read())
            {
                ContentModel s = new ContentModel();

                s.bbs_id = Convert.ToInt32(reader["bbs_id"]);
                //s.bbs_boardID = Convert.ToInt32(reader["bbs_boardID"]);
                s.bbs_title = reader["bbs_title"].ToString();
                s.bbs_content = reader["bbs_content"].ToString();
                s.bbs_sender = reader["bbs_sender"].ToString();
                s.bbs_sendTime = Convert.ToDateTime(reader["bbs_sendTime"].ToString());
                s.bbs_face = reader["bbs_face"].ToString();
                //s.bbs_opTime = Convert.ToDateTime(reader["bbs_opTime"].ToString());
                s.bbs_isTop = reader["bbs_isTop"].ToString();
                s.bbs_toTopTime = Convert.ToDateTime(reader["bbs_toTopTime"]);
                s.bbs_isGood = reader["bbs_isGood"].ToString();
                s.bbs_toGoodTime = Convert.ToDateTime(reader["bbs_toGoodTime"].ToString());
                list.Add(s);
            }
            conn.Close();
            return list;


        }

        /// <summary>
        /// 总条数
        /// </summary>
        /// <returns></returns>
        public int countContent()
        {
            SqlConnection conn = new SqlConnection(strConn);
            conn.Open();
            SqlCommand cmd = new SqlCommand("select COUNT(*) from [tb_bbsContent]", conn);

            int i =Convert.ToInt32(cmd.ExecuteScalar());
            conn.Close();
            return i;
          
        }

 


        /// <summary>
        /// 详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public  ContentModel  xiangContentModel(int id)
        {

            SqlConnection conn = new SqlConnection(strConn);
            conn.Open();
            string str = string.Format("select * from tb_bbsContent where bbs_id={0}", id);
            SqlCommand cmd = new SqlCommand(str, conn);
            SqlDataReader reader = cmd.ExecuteReader();

           ContentModel s = new  ContentModel();

            while (reader.Read())
            {
              

                s.bbs_id = Convert.ToInt32(reader["bbs_id"]);
                //s.bbs_boardID = Convert.ToInt32(reader["bbs_boardID"]);
                s.bbs_title = reader["bbs_title"].ToString();
                s.bbs_content = reader["bbs_content"].ToString();
                s.bbs_sender = reader["bbs_sender"].ToString();
                s.bbs_sendTime = Convert.ToDateTime(reader["bbs_sendTime"].ToString());
                s.bbs_face = reader["bbs_face"].ToString();
                //s.bbs_opTime = Convert.ToDateTime(reader["bbs_opTime"].ToString());
                s.bbs_isTop = reader["bbs_isTop"].ToString();
                s.bbs_toTopTime = Convert.ToDateTime(reader["bbs_toTopTime"]);
                s.bbs_isGood = reader["bbs_isGood"].ToString();
                s.bbs_toGoodTime = Convert.ToDateTime(reader["bbs_toGoodTime"].ToString());
             
            }

            conn.Close();
            return s;

        }


        /// <summary>
        /// 回帖信息表
        /// </summary>
        /// <returns></returns>
        public List<ReplyModel> showReplyModel(int rid)
        {
            SqlConnection conn = new SqlConnection(strConn);
            conn.Open();
            string str = string.Format("select * from tb_bbsReply where [bbsReply_rootID]={0}",rid);
            SqlCommand cmd = new SqlCommand(str, conn);
            SqlDataReader reader = cmd.ExecuteReader();

            List<ReplyModel> list = new List<ReplyModel>();

            while (reader.Read())
            {
                ReplyModel s = new ReplyModel();

                s.bbsReply_id = Convert.ToInt32(reader["bbsReply_id"]);
               
                s.bbsReply_rootID = Convert.ToInt32(reader["bbsReply_rootID"]);
                s.bbsReply_title = reader["bbsReply_title"].ToString();
                s.bbsReply_content = reader["bbsReply_content"].ToString();
                s.bbsReply_sender = reader["bbsReply_sender"].ToString();
                s.bbsReply_sendTime =Convert.ToDateTime( reader["bbsReply_sendTime"].ToString());
                s.bbsReply_face = reader["bbsReply_face"].ToString();


                
                list.Add(s);
            }
            conn.Close();
            return list;


        }



    }
}
